import request from "./useRequests";
import { userinfo } from '@/stores/counter'

export default function getResOrPodcast() {
    const user = userinfo()
    async function getPodcast(page: number = user.pages.podcast.page) {
        try {
            const res = await request({
                method: "get",
                url: `/file/getResOrPoscat`,
                params: {
                    "page": page,
                    "limit": 10,
                    "type": 1,
                }
            })
            user.pages.podcast.total = res.data.data.total
            return res.data.data.list

        } catch (err: any) {
            //alert(err)
        }
    }

    async function getRes(cate: number = 0, page: number = user.pages.res.page) {
        try {
            const res = await request({
                method: "get",
                url: `/file/getResOrPoscat`,
                params: {
                    "page": page,
                    "limit": 10,
                    "type": 2,
                    "cate": cate,
                }
            })
            user.pages.res.total = res.data.data.total
            return res.data.data.list

        } catch (err: any) {
            //alert(err)
        }
    }

    async function getSaying(page: number = user.pages.saying.page) {
        try {
            const res = await request({
                method: "get",
                url: `/file/getResOrPoscat`,
                params: {
                    "page": user.pages.saying.page,
                    "limit": 10,
                    "type": 3,
                }
            })
            user.pages.saying.total = res.data.data.total
            return res.data.data.list

        } catch (err: any) {
            //alert(err)
        }
    }

    return {
        getPodcast, getRes, getSaying
    }
}